package com.qf.utils;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * projectName:day15_autologin
 * author:liuXin
 * time:2022/12/29 14:52
 * description:
 */
public class MD5Util {
    //加密
    public static String md5(String str){
        try {
            //1获取信息摘要
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            byte[] bytes = str.getBytes("UTF-8");

            //自定义算法
            for (int i = 0; i < bytes.length; i++) {
                bytes[i]-=5;
            }

            //2更新数据
            md5.update(bytes);
            //3加密
            byte[] digest = md5.digest();
            //4返回
            return new BigInteger(1,digest).toString(16);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


}
